#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.utils.translation import ugettext_lazy as _
from django.db import models


class Hit(models.Model):
    """
    Represents a hit on the apache server
    """
    url_path = models.CharField(_("URL Path"),
        max_length=255, default='', null=False, blank=False)
    url_qs = models.CharField(_("URL querystring"),
        max_length=255, default='', null=False, blank=False)
    method = models.CharField(_("HTTP Method"),
        max_length=7, default='', null=False, blank=False)
    protocol = models.CharField(_("Protocol"),
        max_length=20, default='', null=False, blank=False)
    code = models.IntegerField(_("HTTP Error Code"),
        default=200, null=False, blank=False)
    hit_at = models.DateTimeField(_("Date Time"), unique=True,
        null=False, blank=False)
    size = models.IntegerField(_("Response Size"),
        default=0, null=False, blank=False)
    user = models.CharField(_("User Identity"),
        max_length=255, default='', null=False, blank=False)
    from_ip = models.CharField(_("Client IP"),
        max_length=15, default='', null=False, blank=False)
    url_referrer = models.CharField(_("Url Referrer"),
        max_length=255, default='', null=False, blank=False)
    user_agent = models.CharField(_("User Agent"),
        max_length=255, default='', null=False, blank=False)

    class Meta:
        db_table = "hit"
        ordering = ("-hit_at", )

    def __unicode__(self):
        return u"%s %s %s %s?%s" % (self.hit_at, self.code, self.method,
            self.url_path, self.url_qs)
